﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Helpers
{
    public class RedisBatchHelper
    {
        private readonly IBatch _batch;
        private readonly string _prefixKey;
        private readonly RedisHelper _redisHelper;

        public RedisBatchHelper(RedisHelper redisHelper)
        {
            _prefixKey = redisHelper.PrefixKey;
            _batch = redisHelper.MyBatch;
            _redisHelper = redisHelper;
        }

        #region zset
        public Task SortedSetAddAsync(RedisKey key, RedisValue member, double score, CommandFlags flags = CommandFlags.FireAndForget)
        {
            return _batch.SortedSetAddAsync(_redisHelper.MergeKey(key), member, score, flags);
        }
        #endregion

        #region hashSet
        public Task HashSetAsync<T>(RedisKey key, RedisValue hashField, T value, When when = When.Always, CommandFlags flags = CommandFlags.FireAndForget)
        {
            return _batch.HashSetAsync(_redisHelper.MergeKey(key), hashField, _redisHelper.ConvertJson(value), when, flags);
        }
        #endregion

        public void Execute()
        {
            _batch.Execute();
        }
    }
}
